package org.kfive.nova.hbase;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.io.Text;

import java.io.IOException;
import java.util.Map;

/**
 * Created by admin on 2017-05-14.
 */
public class HbaseReaderMapper extends TableMapper<Text,Text> {
    @Override
    protected void map(ImmutableBytesWritable key, Result values, Context context) throws IOException, InterruptedException {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<byte[],byte[]> value : values.getFamilyMap("content".getBytes()).entrySet()){
            String str = new String(value.getValue());
            sb.append(new String(value.getKey())).append(":").append(str);
            context.write(new Text(key.get()),new Text(sb.toString()));
        }

    }
}
